package com.byq.mm.abstractx.cluster.server;

import com.byq.mm.abstractx.cluster.server.access.ClientAccessController;
import com.byq.mm.abstractx.cluster.server.access.SecuredServer;
import com.byq.mm.abstractx.cluster.server.executor.Executor;
import com.byq.mm.abstractx.device.Device;
import com.byq.mm.abstractx.engine.CoreEnvironment;
import com.byq.mm.abstractx.protocol.Interaction;


abstract public class ClusterServer extends SecuredServer {
	String cluster;
	Device device;
	ServerIdentifier id;
	public ServerIdentifier getId() {
		return id;
	}


	protected CoreEnvironment env;
	public String getCluster() {
		return cluster;
	}
	public Device getDevice() {
		return device;
	}
	
	
	ClientAccessController accessController;

	public ClusterServer(String cluster, Device device, CoreEnvironment env) {
		super(env);
		this.cluster = cluster;
		this.device = device;
		this.env = env;
		accessController = new ClientAccessController(env, this);
		this.serverAccessController.setProxy(accessController);
		id = new ServerIdentifier(device.getId(), cluster);
	}
	public ClientAccessController getAccessController() {
		return accessController;
	}
	protected Executor getExecutor(){
		return env.getExecutorManager().getExecutor(this.getDevice().getId(), this.getCluster());
	}
	protected Interaction createReport() {
		Interaction i = new Interaction();
		i.direction = Interaction.DIRECTION_FROM_SERVER;
		i.cluster = getCluster();
		i.from = this.getDevice().getId();
		return i;
	}

	
}
